<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
Ext.onReady(function() {
	
	Ext.QuickTips.init();
	
	Ext.define('Student', { 
        extend: 'Ext.data.Model', 
        // fields定义字段和数据类型 
        fields: ['id', 'displayName'] 
    });
	
	Ext.define('Subject', { 
        extend: 'Ext.data.Model', 
        // fields定义字段和数据类型 
        fields: ['id', 'displayName'] 
    });
	
	Ext.define('Chargeback', {
		extend: 'Ext.data.Model',
		fields: ['id','displayName']
	});
	
	var chargebackstates=[{'id':'0','displayName':'不扣占位费'},{'id':'1','displayName':'扣除占位费'}];
	
	var chargebackstore=Ext.create('Ext.data.Store', {
        autoDestroy: true,
        model: 'Chargeback',
        data: chargebackstates
    });
	
	var studentstore=Ext.create('Ext.data.Store', {
        model: 'Student', 
        autoLoad: true,
        //使用ajax代理 
        proxy: { 
            type: 'ajax', 
            url: '../service/student_allstu',
            //Reader 解码json数据 
            reader: { 
                type: 'json', 
                root: 'root', 
                total: 'total'
            }
        }
    });
	
	var subjectstore=Ext.create('Ext.data.Store', {
		model: 'Subject',
		autoload: true,
		proxy: {
			type: 'ajax',
			url: '../service/subject_allsub',
			reader: {
				type: 'json',
				root: 'root',
				total: 'total'
			}
		}
	});
	
	var updateslowform=Ext.widget({
		 	xtype: 'form',
	        layout: 'form',
	        renderTo:'updateslow',
	        frame:true,
	        fieldDefaults: {
	            msgTarget: 'qtip',
	            labelWidth: 80
	        },
	        defaultType: 'textfield',
	        items: [{
	        	id: 'studentid',
	            fieldLabel: '学生',
	            xtype:'combobox',
	            store:studentstore,
	            valueField:'id',
	            editable:false,
	            displayField: 'displayName',
	            name: 'studentid',
	            allowBlank: false
	        },{
	        	id: 'subjectid',
	            fieldLabel: '课程',
	            xtype:'combobox',
	            store:subjectstore,
	            valueField:'id',
	            editable:false,
	            displayField: 'displayName',
	            name: 'subjectid',
	            allowBlank: false
	        },{
	        	id: 'chargebackname',
	            fieldLabel: '占位费',
	            xtype:'combobox',
	            store:chargebackstore,
	            valueField:'id',
	            editable:false,
	            displayField: 'displayName',
                queryMode: 'local',
	            allowBlank: false,
	            listeners: {
	            	select: function(comb, records) {
        	    		Ext.each(records, function(record) {
        	    			Ext.getCmp('chargeback').setValue(record.data.id);
        	    		});
	            	}
	            }
	        },{
	        	id: 'chargeback',
	        	name: 'oaslow.chargeback',
	        	hidden: true
	        },{
	        	id:'slowstart',
	            fieldLabel: '缓修开始时间',
	            xtype: 'datefield',
                format: 'Y-m-d', 
	            name: 'oaslow.slowstart',
	            allowBlank: false
	        },{
	        	id:'slowend',
	            fieldLabel: '缓修结束时间',
	            xtype: 'datefield',
                format: 'Y-m-d', 
	            name: 'oaslow.slowend',
	            allowBlank: false
	        },{
	        	id: 'slowlesson',
	            fieldLabel: '缓修课程',
	            name: 'oaslow.slowlesson',
	            xtype: 'numberfield',
	            minValue: 1,
	            maxValue: 100,
	            allowBlank: false,
	        },{
	        	id:'addstart',
	            fieldLabel: '补修开始时间',
	            xtype: 'datefield',
                format: 'Y-m-d', 
	            name: 'oaslow.addstart',
	            allowBlank: false
	        },{
	        	id:'addend',
	            fieldLabel: '补修结束时间',
	            xtype: 'datefield',
                format: 'Y-m-d', 
	            name: 'oaslow.addend',
	            allowBlank: false
	        },{
	        	id:'addlesson',
	            fieldLabel: '补修课程',
	            name: 'oaslow.addlesson',
	            xtype: 'numberfield',
	            minValue: 1,
	            maxValue: 100,
	            allowBlank: false,
	        }],

       buttons: [{
           text: '确定',
           handler: function() {
        	   this.up('form').getForm().submit({  
                   url : '../service/slow_update',//请求的url地址  
                   method:'post',//请求方式
                   params:{
                	   id: Ext.getDom('slowid').value
                   },
                   success:function(form,action){//加载成功的处理函数  
	                   	Ext.Msg.alert('提示', action.result.msg);
	                   	Ext.getCmp('updateslowwin').close();
              		},
                   failure:function(form,action){//加载成功的处理函数  
 		        		Ext.Msg.alert('提示', action.result.msg); 
  		        	}
               });
       		}
       },{
       	text: '重置',
           handler: function() {
        	   Ext.Ajax.request({
          		    url: '../service/slow_find',
          		    params: {
          		        id: Ext.getDom('slowid').value
          		    },
          		    success: function(response, opts) {
          		        var obj = Ext.decode(response.responseText);
          		        console.log(obj);
          		        Ext.getCmp('studentid').setValue(obj.oaslow.oastudents.id);
          		        Ext.getCmp('subjectid').setValue(obj.oaslow.oasubjects.id);
          		        subjectstore.load();
          		        var chargeback = obj.oaslow.chargeback;
          		        Ext.getCmp('chargeback').setValue(chargeback);
          		        if(chargeback == 1)
          		        	Ext.getCmp('chargebackname').setValue('扣除占位费');
          		        else
          		        	Ext.getCmp('chargebackname').setValue('不扣占位费');
          		        Ext.getCmp('slowstart').setValue(obj.oaslow.slowstart.split('T')[0]);
          		        Ext.getCmp('slowend').setValue(obj.oaslow.slowend.split('T')[0]);
          		        Ext.getCmp('slowlesson').setValue(obj.oaslow.slowlesson);
          		        Ext.getCmp('addstart').setValue(obj.oaslow.addstart.split('T')[0]);
          		        Ext.getCmp('addend').setValue(obj.oaslow.addend.split('T')[0]);
          		        Ext.getCmp('addlesson').setValue(obj.oaslow.addlesson);
          		    },
          		});
           }
       }],
       listeners:{
       	'render':function(){
       		Ext.Ajax.request({
       		    url: '../service/slow_find',
       		    params: {
       		        id: Ext.getDom('slowid').value
       		    },
       		    success: function(response, opts) {
       		        var obj = Ext.decode(response.responseText);
       		        console.log(obj);
       		        Ext.getCmp('studentid').setValue(obj.oaslow.oastudents.id);
       		        Ext.getCmp('subjectid').setValue(obj.oaslow.oasubjects.id);
       		        subjectstore.load();
      		        var chargeback = obj.oaslow.chargeback;
      		        Ext.getCmp('chargeback').setValue(chargeback);
      		        if(chargeback == 1)
      		        	Ext.getCmp('chargebackname').setValue('扣除占位费');
      		        else
      		        	Ext.getCmp('chargebackname').setValue('不扣占位费');
       		        Ext.getCmp('slowstart').setValue(obj.oaslow.slowstart.split('T')[0]);
       		        Ext.getCmp('slowend').setValue(obj.oaslow.slowend.split('T')[0]);
       		        Ext.getCmp('slowlesson').setValue(obj.oaslow.slowlesson);
       		        Ext.getCmp('addstart').setValue(obj.oaslow.addstart.split('T')[0]);
       		        Ext.getCmp('addend').setValue(obj.oaslow.addend.split('T')[0]);
       		        Ext.getCmp('addlesson').setValue(obj.oaslow.addlesson);
       		    },
       		});
       	}
       }
   });
});
</script>
</head>
<body>
<div id="updateslow"></div>
<input type="hidden" id="slowid" value="<s:property value='id'/>"/>
</body>
</html>